﻿ using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using App.Core.Extensions;
using App.Data;
using App.Core.DB;

public partial class UserControls_FeaturedAdds : BaseUserControl
{
    public int MaxAdds { get; set; }
    public RepeatDirection RepeatDirection { get; set; }
    protected void Page_Load(object sender, EventArgs e)
    { 
        BindAdvertisements();
    }

    private void BindAdvertisements()
    {
        BtcHousingEntities context = new BtcHousingEntities();
        UtilityDAO dao =new UtilityDAO();
        DataSet ds = dao.GetDataSet(AppSQL.GET_FEATURED_ADVERTISEMENTS, null, false);
        int counter = ds.Tables[0].Rows.Count > this.MaxAdds ? this.MaxAdds : ds.Tables[0].Rows.Count;

        String html = @"<div style='float:left; margin-right:{0}px; width:155px;'>
                            <img src='{1}/{2}' alt='' title='' style='width:155px;' />
                        </div>";
        StringBuilder sb = new StringBuilder(120);
        if (counter > 0)
        {
            sb.Append("<div style='width:485px; margin:auto auto;'>");
            for (int i = 0; i < counter; i++)
            {
                DataRow row = ds.Tables[0].Rows[i];
                if(i == counter - 1)
                    sb.AppendFormat(html, 0, AppConstants.ADVERTISEMENT_FILES, NullHandler.GetString(row["FileName"]));
                else
                    sb.AppendFormat(html, 10, AppConstants.ADVERTISEMENT_FILES, NullHandler.GetString(row["FileName"]));
            }
            sb.AppendFormat("<div class='clearboth'></div>");
            sb.Append("</div>");
            ltrAdvertisementList.Text = sb.ToString();
        }
    }
}